//import 'package:flutter/material.dart';
//import 'package:flutter_demo/common/Global.dart';
//import 'package:flutter_demo/common/LocalModal.dart';
//import 'package:flutter_demo/common/ThemeModel.dart';
//import 'package:flutter_demo/common/UserModel.dart';
//import 'package:flutter_demo/routes/HomeRoute.dart';
//import 'package:flutter_demo/routes/LoginRoute.dart';
//import 'package:flutter_demo/routes/ThemeChangeRoute.dart';
//import 'package:flutter_demo/widget/BubbleDemoPage.dart';
//import 'package:flutter_demo/widget/ClipDemoPage.dart';
//import 'package:flutter_demo/widget/ControllerDemoPage.dart';
//import 'package:flutter_demo/widget/HonorDemoPage.dart';
//import 'package:flutter_demo/widget/PositionedDemoPage.dart';
//import 'package:flutter_demo/widget/RefreshDemoPage.dart';
//import 'package:flutter_demo/widget/RefreshDemoPage2.dart';
//import 'package:flutter_demo/widget/RefreshDemoPage3.dart';
//import 'package:flutter_demo/widget/ScrollListenerDemoPage.dart';
//import 'package:flutter_demo/widget/ScrollToIndexDemoPage.dart';
//import 'package:flutter_demo/widget/StatusBarDemoPage.dart';
//import 'package:flutter_demo/widget/TagDemoPage.dart';
//import 'package:flutter_demo/widget/TextLineHeightDemoPage.dart';
//import 'package:flutter_demo/widget/TransformDemoPage.dart';
//import 'package:provider/provider.dart';
//
//import 'tab_navigator/TabNavigator.dart';
//
//void main() => Global.init().then((e) => runApp(MyApp()));
//
//class MyApp extends StatelessWidget {
//  @override
//  Widget build(BuildContext context) {
//    // 注册监听
//    return MultiProvider(
//      providers: <SingleChildCloneableWidget>[
//        ChangeNotifierProvider.value(notifier: LocalModel()),
//        ChangeNotifierProvider.value(notifier: ThemeModel()),
//        ChangeNotifierProvider.value(notifier: UserModel()),
//      ],
//      child: Consumer2<ThemeModel, LocalModel>(
//          builder:
//              (BuildContext context, themeModel, localModel, Widget child) =>
//                  MaterialApp(
//                    theme: ThemeData(primarySwatch: themeModel.theme, fontFamily: "PingFang"),
//                    home: MyHomePage(),
//                    routes: <String, WidgetBuilder> {
//                      "login": (context)=> LoginRoute(),
//                      "themes": (context)=> ThemeChangeRoute()
//                    },
//                  )),
//    );
//  }
//}
//
//class MyHomePage extends StatefulWidget {
//  MyHomePage({Key key, this.title}) : super(key: key);
//
//  final String title;
//
//  @override
//  _MyHomePageState createState() => _MyHomePageState();
//}
//
//class _MyHomePageState extends State<MyHomePage> {
//  @override
//  Widget build(BuildContext context) {
//    var routeList = routers.keys.toList();
//    return Scaffold(
////        appBar: AppBar(
////          title: Text("Flutter App"),
////        ),
//        body: tabNavigator()
////        ListView.builder(
////          itemBuilder: (context, index) {
////            return InkWell(
////              child: Card(
////                child: Container(
////                  alignment: Alignment.centerLeft,
////                  margin: EdgeInsets.symmetric(horizontal: 10),
////                  height: 50,
////                  child: Text(list[index]),
////                ),
////              ),
////              onTap: () {
////                Navigator.of(context).pushNamed(routeList[index]);
////              },
////            );
////          },
////          itemCount: list.length,
////        )
//        );
//  }
//}
//
//const list = [
//  "Controller例子",
//  "圆角例子",
//  "滑动监听例子",
//  "滑动到指定位置",
//  "Transform例子",
//  "文本行间距 例子",
//  "简单上下刷新 例子",
//  "简单上下刷新2 例子",
//  "简单上下刷新3 例子",
//  "绝对定位",
//  "弹出提示框例子",
//  "Tag例子",
//  "共享元素 例子",
//  "状态栏颜色"
//];
//
//Map<String, WidgetBuilder> routers = {
//  "widget/controller": (context) {
//    return new ControllerDemoPage();
//  },
//  "widget/clip": (context) {
//    return new ClipDemoPage();
//  },
//  "widget/scroll": (context) {
//    return new ScrollListenerDemoPage();
//  },
//  "widget/scroll_index": (context) {
//    return new ScrollToIndexDemoPage();
//  },
//  "widget/transform": (context) {
//    return new TransformDemoPage();
//  },
//  "widget/text_line": (context) {
//    return new TextLineHeightDemoPage();
//  },
//  "widget/refresh": (context) {
//    return new RefreshDemoPage();
//  },
//  "widget/refresh2": (context) {
//    return new RefreshDemoPage2();
//  },
//  "widget/refresh3": (context) {
//    return new RefreshDemoPage3();
//  },
//  "widget/refresh3": (context) {
//    return new RefreshDemoPage3();
//  },
//  "widget/positioned": (context) {
//    return new PositionedDemoPage();
//  },
//  "widget/bubble": (context) {
//    return new BubbleDemoPage();
//  },
//  "widget/tags": (context) {
//    return new TagDemoPage();
//  },
//  "widget/honor": (context) {
//    return new HonorDemoPage();
//  },
//  "widget/statusbar": (context) {
//    return new StatusBarDemoPage();
//  },
//};

import 'package:flutter/material.dart';
import 'package:flutter_demo/components/MyDialog.dart';
import 'package:flutter_demo/tab_navigator/TabNavigator.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_demo/pages/XyHomePage.dart';
import 'common/Git.dart';
import 'pages/FutureBuilderTest.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter_ScreenUtil',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
     home: tabNavigator(),
      // home: FutureBuilderTest(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    //设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
    return ExampleWidget(title: 'FlutterScreenUtil示例');
  }
}

class ExampleWidget extends StatefulWidget {
  const ExampleWidget({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _ExampleWidgetState createState() => _ExampleWidgetState();
}

class _ExampleWidgetState extends State<ExampleWidget> {
  @override
  Widget build(BuildContext context) {
    printScreenInformation();
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Row(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
                  width: ScreenUtil().setWidth(375),
                  height: ScreenUtil().setHeight(200),
                  color: Colors.red,
                  child: Text(
                    '我的宽度:${ScreenUtil().setWidth(375)}dp \n'
                    '我的高度:${ScreenUtil().setHeight(200)}dp',
                    style: TextStyle(
                        color: Colors.white, fontSize: ScreenUtil().setSp(24)),
                  ),
                ),
                Container(
                  padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
                  width: ScreenUtil().setWidth(375),
                  height: ScreenUtil().setHeight(200),
                  color: Colors.blue,
                  child: Text(
                      '我的宽度:${ScreenUtil().setWidth(375)}dp \n'
                      '我的高度:${ScreenUtil().setHeight(200)}dp',
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: ScreenUtil().setSp(24))),
                ),
              ],
            ),
            Text('设备宽度:${ScreenUtil.screenWidth}px'),
            Text('设备高度:${ScreenUtil.screenHeight}px'),
            Text('设备宽度:${ScreenUtil.screenWidthDp}dp'),
            Text('设备高度:${ScreenUtil.screenHeightDp}dp'),
            Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
            Text('底部安全区距离:${ScreenUtil.bottomBarHeight}dp'),
            Text('状态栏高度:${ScreenUtil.statusBarHeight}dp'),
            Text(
              '实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}',
              textAlign: TextAlign.center,
            ),
            Text(
              '实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}',
              textAlign: TextAlign.center,
            ),
            SizedBox(
              height: ScreenUtil().setHeight(100),
            ),
            Text('系统的字体缩放比例:${ScreenUtil.textScaleFactor}'),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('我的文字大小在设计稿上是24px，不会随着系统的文字缩放比例变化',
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: ScreenUtil().setSp(24),
                    )),
                Text('我的文字大小在设计稿上是24px，会随着系统的文字缩放比例变化',
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: ScreenUtil()
                            .setSp(24, allowFontScalingSelf: true))),
                RaisedButton(
                  onPressed: () {
                    _showAlertDialog();
                  },
                  child: Text('alertDialog'),
                ),
                RaisedButton(
                  onPressed: () {
                    _showSelectDialog();
                  },
                  child: Text('simpleDialog'),
                ),
                RaisedButton(
                  onPressed: () {
                    _showBottomSheet();
                  },
                  child: Text('bottomSheet'),
                ),
                RaisedButton(
                  onPressed: () {
                    _showMyDialog();
                  },
                  child: Text('自定义dialog'),
                )
              ],
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.title),
        onPressed: () {
          ScreenUtil.init(context,
              width: 1500, height: 1334, allowFontScaling: false);
          setState(() {});
        },
      ),
    );
  }

  _showAlertDialog() async {
    var result = await showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('提示框'),
            content: Text('确定要删除吗？'),
            actions: <Widget>[
              FlatButton(
                  onPressed: () {
                    Navigator.pop(context, 'Cancel');
                  },
                  child: Text('取消')),
              FlatButton(
                  onPressed: () {
                    Navigator.pop(context, 'Ok');
                  },
                  child: Text('确定'))
            ],
          );
        });
    print(result);
  }

  _showSelectDialog() async {
    var result = await showDialog(
        context: context,
        builder: (context) {
          return SimpleDialog(
            title: Text('提示框'),
            children: <Widget>[
              SimpleDialogOption(
                  child: Text('A'),
                  onPressed: () {
                    Navigator.pop(context, 'A');
                  }),
              Divider(),
              SimpleDialogOption(
                  child: Text('B'),
                  onPressed: () {
                    Navigator.pop(context, 'B');
                  }),
              Divider(),
              SimpleDialogOption(
                  child: Text('C'),
                  onPressed: () {
                    Navigator.pop(context, 'C');
                  })
            ],
          );
        });
    print(result);
  }


  _showBottomSheet() async {
    var result = await showModalBottomSheet(context: context, builder: (context) {
      return Container(
        height: 200,
        child: Column(
          children: <Widget>[
            ListTile(
              title: Text('A'),
            ),
            ListTile(
              title: Text('B'),
            ),
            ListTile(
              title: Text('C'),
            )
          ],
        ),
      );
    });
  }

  _showMyDialog() async {
    var result = await showDialog(context: context, builder: (context) {
      return MyDialog();
    });
  }

  void printScreenInformation() {
    print('设备宽度:${ScreenUtil.screenWidth}'); //Device width
    print('设备高度:${ScreenUtil.screenHeight}'); //Device height
    print('设备的像素密度:${ScreenUtil.pixelRatio}'); //Device pixel density
    print(
        '底部安全区距离:${ScreenUtil.bottomBarHeight}dp'); //Bottom safe zone distance，suitable for buttons with full screen
    print(
        '状态栏高度:${ScreenUtil.statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px

    print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
    print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');

    print(
        '宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');
    print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');
    print('系统的字体缩放比例:${ScreenUtil.textScaleFactor}');
  }
}
